﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_NH.DB_Map.WorkBill
{
    using NHibernate;
    using NHibernate.Mapping.ByCode;
    using NHibernate.Mapping.ByCode.Conformist;

    using DB_NH.DB_Model.WorkBill;

    public class WorkBill_map : EntityMapping<WorkBill>
    {
        public WorkBill_map()
        {
            //所属工作单类型
            ManyToOne(x => x.BillType, map =>
            {
                map.Column("TypeId");
                map.NotNullable(true);
            });

            //所属项目
            ManyToOne(x => x.Project, map =>
            {
                map.Column("ProjectId");
                map.NotNullable(false);
            });

            //对应的流程ID
            Property(x => x.ApprovalRecordId, map =>
            {
                map.Length(40);
            });

            Property(x => x.BillContent, map =>
            {
                map.Length(90000);
            });

            //创建者
            ManyToOne(x => x.Creator, map =>
            {
                map.Column("CreatorId");
                map.NotNullable(false);
            });

            Property(x => x.BillItems, map =>
            {
                map.Length(90000);
            });

            Property(x => x.WillEndDate, map =>
            {
            });

            Property(x => x.EndDate, map =>
            {
            });

            Property(x => x.EndDescribe, map =>
            {
                map.Length(10000);
            });

            Property(x => x.EndFlag, map =>
            {
            });

            Bag(x => x.Evaluates, map =>
            {
                map.Key(keyMapper => keyMapper.Column("WorkBillId"));
            }, act => act.OneToMany());

            Bag(x => x.Flows, map =>
            {
                map.Key(keyMapper => keyMapper.Column("WorkBillId"));
            }, act => act.OneToMany());

            //执行部门
            ManyToOne(x => x.ExecuteDepartment, map =>
            {
                map.Column("ExecuteDepartmentId");
                map.NotNullable(false);
            });

            //执行者
            ManyToOne(x => x.Executor, map =>
            {
                map.Column("ExecutorId");
                map.NotNullable(false);
            });

            //所属项目
            ManyToOne(x => x.Project, map =>
            {
                map.Column("ProjectId");
                map.NotNullable(false);
            });

            Table(WorkBill.TableName);
        }
    }
}
